home *** CD-ROM | disk | FTP | other *** search
- /* resort.c - resort after last element of array replaced */
- /* uses pointers to actual data elements and compare functions */
- #include "stdio.h"
-
- int resort(pa,na,pcomp)
- char *pa[] ; /* array of pointers to elements to be sorted */
- int na ; /* number of elements to be sorted */
- int (*pcomp) () ; /* pointer to compare function */
- {
- int i , j ; /* indeces for loops */
- char *ptemp ; /* temporary storage of one pointer */
- /* insert the last element into the sorted array */
- i = na - 1 ; /* last element */
- ptemp - pa[i] ;
- j = j - 1 ;
- while( (j >= 0) && (*pcomp)(ptemp,pa[j]) < 0 )
- { pa[j+1] = pa[j] ;
- j = j - 1 ;
- }
- pa[j+1] = ptemp ;
- }
-
-
-
-